﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class more_city : System.Web.UI.Page
{

    ctpDataContext db;
    protected void Page_Load(object sender, EventArgs e)
    {
        db=new ctpDataContext();

        if (!this.IsPostBack)
        {
            this.Panel1.Visible = false;
            this.Panel2.Visible = false;

        }
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

        var city = from p in db.ct_profiles
                   where p.continent == int.Parse(this.ListBox1.SelectedValue) && p.language_no == (int)Session["now_user_lang_no"]
                   select new
                   {
                       country = p.country
                   };

        this.ListBox2.DataSource = city.Distinct();
        this.ListBox2.DataTextField = "country";
        this.ListBox2.DataValueField = "country";
        this.ListBox2.DataBind();

        this.ListBox3.Items.Clear();
        this.ListBox4.Items.Clear();

        this.Panel1.Visible = false;
        this.Panel2.Visible = false;

    }
    protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
    {
        GeoLingManager glManager = new GeoLingManager(Request, Response);
        String _lang = glManager.getLang();
        DatabaseUtil dbUtil = new DatabaseUtil();
        //Get user's preferred langugage in int
        _lang = dbUtil.getLanguageNo(_lang).ToString();

        var city = from p in db.ct_profiles
                   where p.country == this.ListBox2.SelectedValue&&p.language_no==(int)Session["now_user_lang_no"]
                   select new
                   {
                       title = dbUtil.getPropertyPost(p.title, (int)DatabaseUtil.fromTables.ct_profile_title, p.no, _lang),
                       no = p.no
                   };

        this.ListBox3.DataSource = city;
        this.ListBox3.DataTextField = "title";
        this.ListBox3.DataValueField = "no";
        this.ListBox3.DataBind();
        this.ListBox4.Items.Clear();

        this.Panel1.Visible = false;
        this.Panel2.Visible = false;

    }
    protected void ListBox3_SelectedIndexChanged(object sender, EventArgs e)
    {
        GeoLingManager glManager = new GeoLingManager(Request, Response);
        String _lang = glManager.getLang();
        DatabaseUtil dbUtil = new DatabaseUtil();
        //Get user's preferred langugage in int
        _lang = dbUtil.getLanguageNo(_lang).ToString();

        var city = from p in db.ct_s_profiles
                   where p.ct_no ==int.Parse(this.ListBox3.SelectedValue )&& p.valid == true && p.language_no == (int)Session["now_user_lang_no"]
                   select new
                   {
                       title = dbUtil.getPropertyPost(p.title, (int)DatabaseUtil.fromTables.s_profile_title, p.no, _lang),
                       no = p.no
                   };

        this.ListBox4.DataSource = city;
        this.ListBox4.DataTextField = "title";
        this.ListBox4.DataValueField = "no";
        this.ListBox4.DataBind();

        this.HyperLink3.Text = this.ListBox3.SelectedItem.Text;
        this.HyperLink3.NavigateUrl = "city.aspx?no="+this.ListBox3.SelectedValue;

        this.Panel1.Visible = true;
        this.Panel2.Visible = false;
    }
    protected void ListBox4_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.Panel2.Visible = true;
        this.HyperLink4.Text = this.ListBox4.SelectedItem.Text;
        this.HyperLink4.NavigateUrl = "city_s.aspx?no=" + this.ListBox4.SelectedValue;
    }
}
